#include <trax.hpp>
#include "atBVHNode.h"
#include "Ray.h"
#include "HitRecord.h"

namespace AtomTrace{
    atBVHNode::atBVHNode(){
        numTri = -1;
        this->LoadFromGM(0);
    }

    atBVHNode::atBVHNode(int nodeID){
        numTri = -1;
        this->LoadFromGM(nodeID);
    }

    void atBVHNode::LoadFromGM(int nodeID)
    {
        int addr = GetBVH() + nodeID*8; // each node is 8 words
        mBox.pmin.LoadFromGM(addr);
        mBox.pmax.LoadFromGM(addr+3);

        numTri = loadi(addr+6);
        childID = loadi(addr+7);
        
    }

    bool atBVHNode::Intersect(const Ray & ray, float & hit)
    {
        //float tt = hit.t;
        //bool isHit = 
        return this->mBox.Intersect(ray, hit);
        //if(isHit)
        {
            //if(tt > hit.t) return false; // if the hit distrance of the box is father away from the geometry hit, not need to check triangle inside this box
            //RayTracer::TraceTriangles(ray, childID, numTri, hit);          
        }

        //return isHit;
    }

} // namespace AtomTrace
